from django.shortcuts import render, get_object_or_404
from django.views.decorators.http import require_http_methods

from core.models import Article

accordion_data = [
    {
        "title": "Tailwind CSS",
        "description": "This is Tailwind CSS description"
    },
    {
        "title": "Alpine.js",
        "description": "This is Alpine.js description"
    },
    {
        "title": "Vite",
        "description": "This is Vite description"
    },
    {
        "title": "HTMX",
        "description": "This is HTMX description"
    }
]


def index(request):
    context = {"accordion_data": accordion_data}
    return render(request, 'index.html', context)


def article_list(request):
    context = {"articles": Article.objects.all()}
    return render(request, "article_list.html", context)


@require_http_methods(["POST"])
def publish_article(request, pk):
    article = get_object_or_404(Article, pk=pk)
    article.published = True
    article.save()
    return render(request, "article_row.html", {"article": article})
